<template>
	<view class="home">
		<test v-if="flag" v-bind:title="title" @myEven="getNum"></test>
		<button @click="change">更改flag</button>
		<view>这是子组件传递过来的值{{num}}</view>
		<test-a></test-a>
		<test-b></test-b>
		<swiper indicator-dots circular>
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<view class="nav">
			<view class="nav_item" v-for="item,index in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
			
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<goods-list @goodsItemClick="goGoodDetails" :goods="goods"></goods-list>
		</view>
	</view>
</template>

<script>
	import test from "../../components/test.vue"
	import testA from "../../components/a.vue"
	import testB from "../../components/b.vue"
	import goodsList from "../../components/goods-list.vue"
	export default {
		data() {
			return {
				title: 'Hello',
				flag: true,
				num: 0,
				swipers: [],
				goods: [],
				navs: [
					{
						icon: 'iconfont icon-ziyuan',
						title: '黑马超市',
						path: '/pages/goods/goods'
					},
					{
						icon: 'iconfont icon-guanyuwomen',
						title: '登录页面',
						path: '/pages/login/login'
					},
					{
						icon: 'iconfont icon-tupian',
						title: '社区图片',
						path: '/pages/pics/pics'
					},
					{
						icon: 'iconfont icon-shipin',
						title: '学习视频',
						path: '/pages/videos/videos'
					}
				]
				
			}
		},
		onLoad() {
			this.getLunbo()
			this.getHotGoods()
		},
		methods: {
			goGoodDetails(id){
				uni.navigateTo({
					url:'/pages/goods-detail/goods-detail?id=' + id
				})
			},
			change(){
				this.flag = !this.flag
			},
			getNum(num) {
				console.log(num)
				this.num = num
			},
			async getLunbo() {
				// console.log("获取轮播图...")
				// uni.request({
				// 	url:"http://localhost:8082/api/getlunbo",
				// 	success: (res) => {
				// 		console.log(res)
				// 		if(res.data.status != 0) {
				// 			return uni.showToast({
				// 				title: "获取数据失败"
				// 			})
				// 		}
				// 		this.swipers = res.data.message
				// 	}
				// })
				const res = await this.$myRequest({
					url: '/api/getlunbo'
				})
				this.swipers = res.data.message
				
				console.log(res)
			},
			async getHotGoods() {
				const res = await this.$myRequest({
						url: '/api/getgoods?pageindex=1'
					})
					console.log(res)
					this.goods = res.data.message
			}, 
			navItemClick(url) {
				uni.navigateTo({
					url: url
				})
				console.log(url)
			}

		},
		components:{
			test: test,
			"test-a": testA,
			"test-b": testB,
			"goods-list": goodsList
		}
	}
</script>

<style lang="scss">
	
	
	// .home {
	// 	display: flex;
	// 	flex-direction: column;
	// 	align-items: center;
	// 	justify-content: center;
	// 	swiper{
	// 		width: 750rpx;
	// 		height: 380rpx;
	// 		image{
	// 			width: 100%;
	// 			height: 100%;
	// 		}
	// 	}
	// }
	
	.nav{
		display: flex;
		.nav_item{
			width: 25%;
			text-align: center;
			view{
				width: 120rpx;
				height: 120rpx;
				background: $shop-color;
				border-radius: 60rpx;
				margin: 10px 15px;
				line-height: 120rpx;
				color: #fff;
				font-size: 50rpx;
			}
			text{
				font-size: 30rpx;
			}
		}
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	
	.hot_goods {
		background: #eee;
		overflow: hidden;
		margin-top: 10px;
		.tit{
			height: 50px;
			line-height: 50px;
			color: $shop-color;
			letter-spacing: 20px;
			background-color: #FFFFFF;
			text-align: center;
			margin: 7rpx 0;
		}
		
	}
</style>
